from pydantic_settings import BaseSettings, SettingsConfigDict
from typing import Optional


class Settings(BaseSettings):
    # 配置设置
    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        extra='allow'
    )

    # 定义配置字段
    database_url: Optional[str] = None
    secret_key: str | None = None
    algorithm: str | None = None
    access_token_expire_minutes: int | None = None
    redis_url: Optional[str] = None

    # 应用基本配置
    APP_NAME: str = "My FastAPI App"
    DEBUG: bool = False

    # 数据库配置
    DB_HOST: str = "127.0.0.1"
    DB_PORT: int = 3306
    DB_USER: str = "root"
    DB_PASSWORD: str = "123456"
    DB_NAME: str = "fastapi"

    # 外网API配置
    EXTERNAL_API_URL: str = ""
    EXTERNAL_API_KEY: str = ""

    # 缓存配置
    CACHE_ENABLED: bool = True
    CACHE_TIMEOUT: int = 60 * 15  # 15分钟


# 全局配置实例
settings = Settings()
